function FlushBuffer()
{
    for(tmp=0; tmp<buffer_count; tmp++)
    {   print a_buffer[tmp];   }
    buffer_count=0;
}

function StoreBuffer(db_h_line)
{
    a_buffer[buffer_count]=a_db_h[db_h_line];
    buffer_count++;
}

function ClearBuffer()
{
    buffer_count=0;
}

BEGIN {
    db_h_lines=0;  table_h_lines=0;
    append_flag=1;
    ClearBuffer();
}
FILENAME==ARGV[1] {
    a_db_h[db_h_lines]=$0;
    db_h_lines++;
}
FILENAME==ARGV[2] {
    a_table_h[table_h_lines]=$0;
    table_h_lines++;
}
END {
    db_h_count=0;
    for(db_h_count=0; db_h_count<db_h_lines; db_h_count++)
    {
        if(a_db_h[db_h_count] ~ /typedef struct/)
        {  FlushBuffer();  }
        else
        {
            if(a_db_h[db_h_count] ~ a_table_h[table_h_lines-1])
            {
                for(tmp=0; tmp<table_h_lines; tmp++)
                {   print a_table_h[tmp];   }
                ClearBuffer();
                append_flag=0;
                break;
            }
        }
        StoreBuffer(db_h_count);
    }
    FlushBuffer();
    if(append_flag)
    {
        for(tmp=0; tmp<table_h_lines; tmp++)
        {   print a_table_h[tmp];   }
        print;
    }
    else
    {
        for(tmp=db_h_count+1; tmp<db_h_lines; tmp++)
        {   print a_db_h[tmp];   }
    }
}
